package top.canyue.word_range_service.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.canyue.word_range.pojo.dto.EventDto;
import top.canyue.word_range.pojo.dto.PageDTO;
import top.canyue.word_range.pojo.query.EventQuery;
import top.canyue.word_range.pojo.vo.EventVo;
import top.canyue.word_range.result.Result;
import top.canyue.word_range_service.service.EventService;

/**
 * 活动相关接口
 * @author canyue
 */

@RestController
@RequestMapping(value = "/apiV1/event")
@RequiredArgsConstructor
public class EventController {
    final EventService eventService;


    ///  添加活动
    @PostMapping("/")
    public Result<EventVo> addEvent(@RequestHeader String JWT, @RequestBody EventDto event){
        return eventService.addEvent(event);
    }

    /// 更新活动
    @PutMapping("/")
    public Result<EventVo> updateEvent(@RequestHeader String JWT, @RequestBody EventDto event){
        return eventService.updateEvent(event);
    }

    /// 基于ID获取活动
    @GetMapping("/{id}")
    public Result<EventVo> getEventById(@RequestHeader String JWT, @PathVariable String id){
        return eventService.getEventById(id);
    }

    /// 基于ID删除活动
    @DeleteMapping("/{id}")
    public Result<EventVo> deleteEventById(@RequestHeader String JWT, @PathVariable Long id){
        return eventService.deleteEventById(id);
    }

    /// 获取活动列表
    @GetMapping("/list")
    public PageDTO<EventVo> getEventList(@RequestHeader String JWT, EventQuery query){
        return eventService.getEventList(query);
    }

    /// 参加活动
    @PostMapping("/participate/{eventId}")
    public Result<EventVo> participateEvent(@RequestHeader String JWT,@PathVariable String eventId){
        return eventService.participateEvent(eventId);
    }

    /// 完成活动
    @PostMapping("/finish/{eventId}")
    public Result<EventVo> finishEvent(@RequestHeader String JWT,@PathVariable String eventId){
        return eventService.finishEvent(eventId);
    }


}
